package com.minyifang.wcspf.work.ui.user.presenter;

import com.google.gson.Gson;
import com.minyifang.wcspf.common.base.BasePresenter;
import com.minyifang.wcspf.common.config.network.Constants;
import com.minyifang.wcspf.common.config.network.RetrofitHelper;
import com.minyifang.wcspf.common.config.user.UserManager;
import com.minyifang.wcspf.common.md5.SafeUtils;
import com.minyifang.wcspf.common.utils.LogUtil;
import com.minyifang.wcspf.work.ui.user.model.DepositBean;
import com.minyifang.wcspf.work.ui.user.view.YaJinDetailsView;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by LuoYaWei on 2018/9/6.
 */
public class YaJinDetailsPresenter extends BasePresenter<YaJinDetailsView> {
    public void getDetail(String orderId) {
        getView().showLoadingView();
        Map<String, Object> map = new HashMap<>();
        map.put("orderId", orderId);
        JSONObject aesJsonData = Constants.getAESJsonData(map, UserManager.getInstance().getToken());
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), aesJsonData.toString());
        addTask(RetrofitHelper.getInstance().getService().getDepositDetails(requestBody), respond -> {
            getView().hideLoadingView();
            if (respond.result == 1) {
                LogUtil.e("押金明细：" + SafeUtils.decrypt(respond.data));
                DepositBean bean = new Gson().fromJson(SafeUtils.decrypt(respond.data), DepositBean.class);
                getView().showDetail(bean);
            } else
                getView().showRequestFailed(respond.message);
        });
    }
}
